package com.inspur.dgov.bsp.system.feign;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.inspur.dgov.bsp.system.entity.PubDict;
import com.inspur.dgov.bsp.system.service.PubDictService;
import com.inspur.dgov.common.tool.api.R;
import org.apache.commons.configuration.DatabaseConfiguration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 系统管理 Feign接口实现
 *
 * @Author chiyupei
 * @Date 19/11/15 下午3:35
 * @Version 1.0
 * @Description 系统管理 Feign接口实现
 */
@RestController
public class SystemFeign implements ISystemFeign {

    @Autowired
    private PubDictService pubDictService;

    /**
     * 注入数据库常量配置
     */
    @Resource(name="databaseConfiguration")
    public DatabaseConfiguration systemConstant;

    /**
     * 根据字典ID集合获取字典列表
     *
     * @param ids  字典ID集合
     * @return
     */
    @Override
    public R<List<PubDict>> dictListByIds(String ids) {
        List<String> list = StrUtil.split(ids,',');
        List<PubDict> dictList = this.pubDictService.list(new QueryWrapper<PubDict>().lambda().in(PubDict::getId, list));
        return R.data(dictList);
    }

    /**
     * 根据系统配置项KEY获取系统配置项值
     *
     * @param configKey  系统配置项KEY
     * @return
     */
    @Override
    public R<String> sysConfig(String configKey) {
        String congfigValue = this.systemConstant.getString(configKey, "");
        return R.data(congfigValue);
    }
}
